#include <SGE.h>

using namespace SGE;

#include "FrontendState.h"
#include "PlayState.h"
#include "HelpState.h"

GameState* currentState = nullptr;
NextState nextState = Frontend;
GameContext gameContext;
SGE_Sound backgroundMusic;

void SGE_Initialize()
{
	backgroundMusic.Load("monkeysspinningmonkeys.mp3");
	backgroundMusic.Play(true);
}

void SGE_Terminate()
{
	backgroundMusic.Unload();
}

bool SGE_Update(float deltaTime)
{
	//if there is no state
	if(nextState != None)
	{
		if(currentState != nullptr)
		{
			currentState -> Unload();
			delete currentState;
		}

		//change state
		switch(nextState)
		{
			case Frontend:
				currentState = new FrontendState(gameContext);
				break;
			case Gameplay:
				currentState = new PlayState(gameContext);
				break;
			case Help:
				currentState = new HelpState(gameContext);
		}

		//load new current state
		currentState -> Load();
	}

	nextState = currentState -> Update(deltaTime);

	if(nextState == Quit)
	{
		currentState -> Unload();
		delete currentState;
		return true;
	}
	return false;
}

void SGE_Render()
{
	currentState -> Render();
}